home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / Xprof / xprof / error.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  4KB  |  118 lines

  1. /*==================================================================
  2.  *      File :          error.c
  3.  *      Package:        Xprof
  4.  *
  5.  *      Author :        Aloke Gupta.
  6.  *
  7.  *  (C) Copyright 1992, Aloke Gupta.
  8.  *==================================================================*/
  9.  
  10. /*
  11.  * Processing routines for the errors seen in the message stream.
  12.  * Functions:
  13.  *    1. process_error(FILE *fp, char *string, GlobalStats *gstats)
  14.  *    2. print_error_stats(FILE *fp)
  15.  *    3. The routines to process each error seen. These have the format:
  16.  *           Error(FILE *fp, error_index, current_time)
  17.  */
  18.  
  19. #include <stdio.h>
  20. #include "common.h"
  21.  
  22. MsgStats TotalErrorStats;        /* Overall stats for all errors */
  23. MsgStats ErrorStats[MAXERRORS];        /* Detailed stats for each error */
  24.  
  25. /*static char in_string[MAXSTRINGSIZE];*/  /* Buffer to read a record into */
  26. static char sbuf[132];            /* Temp. slots for sscanf*/
  27.  
  28. extern MsgType ErrorType[];
  29. extern int lookup_error();
  30.  
  31. process_error(fp, string, gstats)
  32. FILE *fp;
  33. char *string;
  34. GlobalStats *gstats;
  35. {
  36.     char error_name[80];        /* Name of the current error */
  37.     int error_index;            /* Index in the data structures */
  38.     long bytes=0;            /* number of bytes */
  39.  
  40.     if (TotalErrorStats.invoked == FALSE)
  41.     InitMsgStats(&TotalErrorStats, gstats->current_time, DETAILED, GRAIN1);
  42.  
  43.     sscanf(string, "%s %s",sbuf, error_name);
  44.     error_index = lookup_error(error_name);
  45.  
  46.     /* Call the action for this error */
  47.     bytes=ErrorType[error_index].action(fp, error_index, gstats->current_time);
  48.  
  49.     /*
  50.      * Fill the data structures for all the errors.
  51.      */
  52.     FillMsgStats(&TotalErrorStats, gstats->current_time, bytes, bytes);
  53.  
  54.     gstats->error_bytes += bytes;
  55.  
  56.  
  57. }
  58.  
  59. print_error_stats(fp)
  60. FILE *fp;
  61. {
  62.     int i;
  63.     char *dashes = "---------------------------------------------------------------" ;
  64.  
  65.  
  66.     if (TotalErrorStats.invoked == FALSE)
  67.         return;
  68.     /*
  69.      * Print the details for all Errors together 
  70.      */
  71.     PrintMsgStats(fp, &TotalErrorStats, "ERRORS ");
  72.  
  73.     /*
  74.      * Brief table for the numbers and byte totals for the errors
  75.      */
  76.     fprintf(fp,"\t%s\n", dashes);
  77.     fprintf(fp,"%-25s",  "        ERROR  messages");
  78.     fprintf(fp,"%25s",  "Total Bytes      ");
  79.     fprintf(fp," %19s\n","Number      ");
  80.     fprintf(fp,"\t%s\n", dashes);
  81.     for (i = 0; i < MAXERRORS; i++)
  82.       if (ErrorStats[i].invoked == TRUE) {
  83.     fprintf(fp,"%-25s", ErrorType[i].name);
  84.     fprintf(fp," %10ld bytes",ErrorStats[i].total_bytes);
  85.     fprintf(fp," (%5.2f%%)", (float) 100 * ErrorStats[i].total_bytes / 
  86.                 TotalErrorStats.total_bytes);
  87.     fprintf(fp," %10ld", ErrorStats[i].number );
  88.     fprintf(fp," (%5.2f%%)", (float) 100 * ErrorStats[i].number / 
  89.                 TotalErrorStats.number);
  90.         fprintf(fp,"\n");
  91.     }
  92.     fprintf(fp,"\t%s\n", dashes);
  93.     fprintf(fp,"\t%s\n", dashes);
  94.     fprintf(fp,"%25s"," Grand Total      ");
  95.     fprintf(fp," %10ld bytes         ", TotalErrorStats.total_bytes);
  96.     fprintf(fp," %10ld         \n", TotalErrorStats.number);
  97.     fprintf(fp,"\t%s\n", dashes);
  98.     fprintf(fp,"\t%s\n", dashes);
  99.     if (verboselevel > 0) {
  100.     for (i = 0; i < MAXERRORS; i++)
  101.       if (ErrorStats[i].detailed == DETAILED) 
  102.           PrintMsgStats(fp, &ErrorStats[i], ErrorType[i].name);
  103.     }
  104.     /*
  105.      * Now dump the raw statistics for the messages
  106.      */
  107.     if (verboselevel > 1) {
  108.     if (TotalErrorStats.detailed == DETAILED)
  109.               PrintMsgDetails(fp, &TotalErrorStats, "ERRORS ");
  110.  
  111.     for (i = 0; i < MAXERRORS; i++)
  112.       if (ErrorStats[i].detailed == DETAILED) 
  113.           PrintMsgDetails(fp, &ErrorStats[i], ErrorType[i].name);
  114.     }
  115.     return;
  116. }
  117.  
  118.